package kr.aow.web.listener;

import java.util.Map;

import javax.servlet.http.HttpSessionAttributeListener;
import javax.servlet.http.HttpSessionBindingEvent;

import kr.aow.vo.MemberDTO;


/**
 * Application Lifecycle Listener implementation class MySessionAttributeListener
 *
 */

public class MySessionAttributeListener implements HttpSessionAttributeListener {

    /**
     * Default constructor. 
     */
    public MySessionAttributeListener() {
        // TODO Auto-generated constructor stub
    }

	/**
     * @see HttpSessionAttributeListener#attributeRemoved(HttpSessionBindingEvent)
     */
    public void attributeRemoved(HttpSessionBindingEvent arg0) {
       String attrName = arg0.getName();
       if("idInSession".equals(attrName)){
    	   MemberDTO member = (MemberDTO) arg0.getValue();
    	   Map<String, MemberDTO> userList = (Map<String, MemberDTO>) arg0.getSession().getServletContext().getAttribute("userList");
    	   userList.remove(member.getMb_id());
       }
    }

	/**
     * @see HttpSessionAttributeListener#attributeAdded(HttpSessionBindingEvent)
     */
    public void attributeAdded(HttpSessionBindingEvent arg0) {
        // TODO Auto-generated method stub
    	String attrName = arg0.getName();
    	if("idInSession".equals(attrName)){
    		Map<String, MemberDTO> userList = (Map<String, MemberDTO>) arg0.getSession().getServletContext().getAttribute("userList");
    		MemberDTO member = (MemberDTO) arg0.getValue();
    		userList.put(member.getMb_id(), member);
    	}
    }

	/**
     * @see HttpSessionAttributeListener#attributeReplaced(HttpSessionBindingEvent)
     */
    public void attributeReplaced(HttpSessionBindingEvent arg0) {
        // TODO Auto-generated method stub
    }
	
}
